package com.yan.proxy.dynamic.jdk;

import com.yan.proxy.IGamePlayer;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class GamePlayerJDKProxy implements InvocationHandler {
    private Object gamePlayer;

    public GamePlayerJDKProxy(Object gamePlayer) {
        this.gamePlayer = gamePlayer;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (!(gamePlayer instanceof IGamePlayer)) {
            throw new IllegalAccessException("");
        }
        System.out.println("走了个动态代理~， 当前方法名：" + method.getName());
        return method.invoke(gamePlayer, args);
    }
}
